Skip to content

Conversation

marekdedic
Copy link
Contributor

No description provided.

Copy link

changeset-bot bot commented Sep 4, 2025

🦋 Changeset detected

Latest commit: 1f6450e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
eslint-plugin-svelte Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

github-actions bot commented Sep 4, 2025

Try the Instant Preview in Online Playground

ESLint Online Playground

Install the Instant Preview to Your Local

npm i https://pkg.pr.new/eslint-plugin-svelte@1f6450e

Published Instant Preview Packages:

View Commit

@marekdedic marekdedic force-pushed the prefer-svelte-reactivity-returned-vars branch 3 times, most recently from 0441041 to a299b31 Compare September 4, 2025 23:32
@marekdedic marekdedic marked this pull request as ready for review September 4, 2025 23:33
Copy link
Member

@baseballyama baseballyama left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why should we be forced to use SvelteSet or SvelteMap even when the values aren’t changing?

@marekdedic
Copy link
Contributor Author

Firstly, this PR is part of a wider effort to move the rule to better detect when variables are "encapsulated" inside a function/class and not report them - this PR is an off-shoot of #1287

But this should make sense even on its own anyway - but I think it does. Example

fileA:

function makeSet() {
  const a = new Set();
  // Populate the set etc.
  return a;
}

export makeSet;

fileB:

<script>
  import { makeSet } from "fileA";

  const a = makeSet();
</script>

<!-- Print the set here -->

<button onclick={a.add(42);}>Click me!</button>

In this example, this PR reports the incorrect usage of Set. I hope to pair it with the rest of #1287 to ignore all encapsulated uses by default so that we don't get too many FPs.

@marekdedic marekdedic force-pushed the prefer-svelte-reactivity-returned-vars branch 2 times, most recently from 5774d2f to 4f23b63 Compare September 21, 2025 08:49
@marekdedic marekdedic force-pushed the prefer-svelte-reactivity-returned-vars branch from 4f23b63 to 22b93d5 Compare September 23, 2025 14:39
@ota-meshi ota-meshi force-pushed the prefer-svelte-reactivity-returned-vars branch from 22b93d5 to 1f6450e Compare September 24, 2025 01:15
}
</script>

{fn().has(42)}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. This is actually fine as is, right? (It shouldn't be reported, right?)
Could you change it to track the value the function returns, check if there's a mutation, and only report that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been thinking about this more and you are right. I think this needs a change of approach. I will probably make an alternative PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants